package action;

import java.util.List;
import java.util.Map;

import entity.House;
import dao.HouseDao;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class ShowHouseAction extends ActionSupport{
	private int pageno;
	private int pagecount;
	public int getPagecount() {
		return pagecount;
	}

	public void setPagecount(int pagecount) {
		this.pagecount = pagecount;
	}

	

	public int getPageno() {
		return pageno;
	}

	public void setPageno(int pageno) {
		this.pageno = pageno;
	}



	private List<House> list;

	public List<House> getList() {
		return list;
	}

	public void setList(List<House> list) {
		this.list = list;
	}

	@Override
	public String execute() throws Exception {
		HouseDao dao = new HouseDao();
		int indexcount = dao.findAll().size();
		int pagesize = 5;
		if(pageno <= 0){
			pageno =1;
		}
		if(indexcount>=pagesize){
			if(indexcount % pagesize == 0){
				pagecount = indexcount / pagesize;
			}else{
				pagecount = indexcount / pagesize +1;
			}
		}else{
			pagecount = 1;
		}
		if(pageno >= pagecount){
			pageno = pagecount;
		}
		List<House> hlist = dao.findAll(pageno, pagesize);
		Map<String, Object> session = ActionContext.getContext().getSession();
		session.put("pageno", pageno);
		session.put("pagecount", pagecount);
		session.put("hlist",hlist);
		return SUCCESS;
		
	}
	

}
